package com.JZ.QM.controller;

import com.JZ.QM.common.entity.FdShareInfoEntity;
import com.JZ.QM.common.entity.ShareInfoEntity;
import com.JZ.QM.common.utils.CommonResult;
import com.JZ.QM.service.FdShareInfoService;
import com.JZ.QM.service.ProductLibraryInfoService;
import com.JZ.QM.service.ShareInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigInteger;
import java.util.List;


/**
 * @author lyp
 * @email lyp@gmail.com
 * @date 2020/6/15 15:24
 */

@RestController
@RefreshScope
@RequestMapping("/productLibratyInfo")
@Slf4j
public class ProductLibraryInfoController {

    @Resource
    private FdShareInfoService fdShareInfoService;

    @Resource
    private ShareInfoService shareInfoService;

    @Resource
    private ProductLibraryInfoService productLibraryInfoService;

    /**
     * 获取基金备选库列表
     * @return
     */
    @RequestMapping("/allFundInfo")
    public CommonResult allFundInfo(){
        //获取所有基金产品基本信息
        List<FdShareInfoEntity> fdShareInfoList = fdShareInfoService.list();

        if (!fdShareInfoList.isEmpty()){
            return CommonResult.success().put("fdShareInfoList",fdShareInfoList);
        } else {
            return CommonResult.error(201,"基金备选产品数据为空");
        }
    }

    /**
     * 获取股票备选库列表
     * @return
     */
    @RequestMapping("/allStockInfo")
    public CommonResult allStockInfo(){
        //获取所有股票产品基本信息
        List<ShareInfoEntity> shareInfoList = shareInfoService.list();

        if (!shareInfoList.isEmpty()){
            return CommonResult.success().put("shareInfoList",shareInfoList);
        } else {
            return CommonResult.error(201,"股票备选产品数据为空");
        }
    }

    /**
     * 获取成分产品id
     * @param proTsCode
     * @return
     */
    @RequestMapping("/getProId")
    public CommonResult getProId(String proTsCode){

        Long proId = productLibraryInfoService.getProId(proTsCode);

        return CommonResult.success().put("proId",proId);
    }

    /**
     * 获取成分产品名称
     * @param proTsCode
     * @return
     */
    @RequestMapping("/getProName")
    public CommonResult getProName(String proTsCode){

        String proName = productLibraryInfoService.getProName(proTsCode);

        return CommonResult.success().put("proName",proName);
    }

    /**
     * 获取成分产品类型
     * @param proId
     * @return
     */
    @RequestMapping("/getProType")
    public CommonResult getProType(Long proId){
        // 1 是股票  0 是基金
        Integer proType = productLibraryInfoService.getProType(proId);

        return CommonResult.success().put("proType",proType);
    }

}
